blog

Home / DeveloperSection / Blogs / Inline Function in C++

Inline Function in C++

priyanka kushwaha2243 05-Feb-2015

In this blog, I’m explaining about Inline function in C++

What is Inline function?

C++ provides an inline functions to reduce the function call overhead. Inline function is a function that is expanded in line when it is called. When the inline function is called whole code of the inline function gets inserted at the point of inline function call. This substitution is performed by the c++ compiler at compile time. Inline function may increase efficiency if it is small.

Example:

 

#include"stdafx.h"
#include<iostream>
usingnamespace std;
usingnamespace System;
inlinedouble Max(double x,double y);
 publicclassInLineClass
{
public:
            double Max(doublex,doubley)
{
            return(x>y)?x:y;
}
 
int Max(intx,inty)
            {
            return(x>y)?x:y;
}
 };
 
 publicclassDriveClass:InLineClass
{
public:
           
 
 };
// Main function  for the program
int main(array<System::String ^> ^args)
{
            DriveClass DriveRef;
             InLineClass BaseRef
            double firstNum,SecNum,result;
            cout<<"Enter a number";
            cin>>firstNum;
            cout<<"Enter another number";
            cin>>SecNum;
            if(firstNum==SecNum)
            {
                        result=firstNum;
                        cout<<"Equal No.=";
            }
            else
            {
                        result= DriveRef.Max(firstNum,SecNum);// error
                        result= BaseRef.Max(firstNum,SecNum);//Right
            cout<<"Greater No.=";
 
            }
                        cout<<result;
            Console::ReadKey();
            return 0;
}

 

Note: Inline function cannot inherit in Drive class.


Updated 05-Feb-2015

Leave Comment

Comments

Liked By